﻿package tests;
import flash.display.Graphics;
import flash.display.Shape;
import flash.Lib;
import flash.text.TextField;
import fpc.controls.buttons.Button;
import fpc.containers.Container;
import fpc.layouts.ExcessSpaceMode;
import fpc.layouts.GridLayout;
import fpc.FoolProofComponents;
import fpc.layouts.ILayout;
import fpc.layouts.ILineLayout;
import fpc.layouts.SimpleGridLayout;
import fpc.controls.Spacer;

class GridLayoutTest extends GenericTest
{
	public function new() 
	{
		super();
	}
	
	var _shape:Shape;
	
	override function init()
	{
		FoolProofComponents.initStage(stage);
		
		_shape = new Shape();
		addChild(_shape);
		
		//layout0();
		//layout1();
		//layout2();
		layout3();
		//simpleGridLayoutTest();
	}
	
	var _container:Container<ILayout>;
	
	function layout0()
	{
		var container = new Container<GridLayout>(new GridLayout());
		_container = cast container;
		container.width = 500;
		container.height = 200;
		container.addTo(this);
		
		var layout = container.layout;
		layout.gapX = 10;
		layout.gapY = 10;
		layout.graphics = _shape.graphics;
		layout.setColSize(0, 150);
		layout.setRowPercents(0, 50);
		layout.setRowPercents(1, 50);
		layout.setRowPercents(2, 50);
		layout.setRowPercents(3, 100);
		layout.setRowPercents(4, 50);
		layout.setRowPercents(5, 50);
		layout.autoSize = false;
		
		var button = new Button('Button              00');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 0, 0);
		
		var button = new Button('Button     10');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 1, 0);
		
		var button = new Button('Button    0102');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 0, 1, 0, 2);
		
		var button = new Button('Button                20');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 2, 0);
		
		var button = new Button('Button       05');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 0, 5);
		
		var button = new Button('Button   1525');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 1, 5, 2, 5);
		
		var button = new Button('Button 31');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 3, 1);
		
		var button = new Button('Button 32');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 3, 5);
		
		layout.add(new Spacer().setYSize(0, 100, 0, 100), 0, 4);
		
		var button = new Button('Button 14');
		button.height = 20;
		button.percentsWidth = 100;
		layout.add(button, 1, 4);
		
		/*var button = new Button('Button 13');
		layout.add(button, 1, 3);*/
		
		layout.add(new Spacer().setYSize(0, 100, 0, 20), 1, 3);
		
		var button = new Button('Button 3334');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 3, 2, 3, 4);
	}
	
	function layout1()
	{
		var container = new Container<GridLayout>(new GridLayout());
		_container = cast container;
		container.width = 500;
		container.height = 200;
		container.addTo(this);
		
		var layout = container.layout;
		layout.excessSpaceModeX = ExcessSpaceMode.MOVE_TO_EDGES(.5);
		layout.gapX = 0;
		layout.gapY = 10;
		layout.graphics = _shape.graphics;
		layout.autoSize = false;
		
		layout.add(new Spacer().setXSize(0, 100).setYSize(20), 0, 0, 5, 0);
		layout.add(new Spacer().setXSize(0, 100, 10).setYSize(1), 0, 1);
		layout.add(new Spacer().setXSize(0, 100, 0, 20).setYSize(20), 1, 1);
		layout.add(new Spacer().setXSize(0, 100, 50, 100).setYSize(1), 2, 1);
		layout.add(new Spacer().setXSize(0, 100, 10, 20).setYSize(20), 3, 1);
		layout.add(new Spacer().setXSize(0, 100, 10, 100).setYSize(1), 4, 1);
		layout.add(new Spacer().setXSize(0, 100, 10, 20).setYSize(20), 5, 1);
		layout.add(new Spacer().setXSize(0, 100, 10, 20).setYSize(1), 6, 1);
	}
	
	function layout2()
	{
		var container = new Container<GridLayout>(new GridLayout());
		_container = cast container;
		container.x = 100;
		container.y = 50;
		container.addTo(this);
		
		var layout = container.layout;
		layout.autoSize = false;
		layout.graphics = _shape.graphics;
		layout.gapX = 0;
		layout.gapY = 0;
		_shape.x = container.x;
		_shape.y = container.y;
		
		var button = new Button('Button 0');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 0, 0, 1, 2);
		
		/*var button = new Button('Button 1');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 0, 1);*/
		
		var button = new Button('Button 2');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 0, 2);
		
		var button = new Button('Button 3');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 0, 3);
		
		var button = new Button('Button 4');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 1, 0);
		
		var button = new Button('Button 5');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 1, 1);
		
		var button = new Button('Button 6');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 1, 2, 1, 2);
		
		/*var button = new Button('Button 7');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 1, 3);*/
	}
	
	function layout3()
	{
		var container = new Container<GridLayout>(new GridLayout());
		_container = cast container;
		container.x = 100;
		container.y = 50;
		container.addTo(this);
		
		var layout = container.layout;
		layout.autoSize = false;
		layout.graphics = _shape.graphics;
		layout.gapX = 0;
		layout.gapY = 0;
		layout.excessSpaceModeX = ExcessSpaceMode.UNIFORM;
		_shape.x = container.x;
		_shape.y = container.y;
		
		var button = new Button('Button 0');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 0, 0, 1, 2);
		
		var button = new Button('Button 2');
		//button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 0, 2);
		
		var button = new Button('Button 3');
		//button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 0, 3);
		
		var button = new Button('Button 4');
		//button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 1, 0);
		
		var button = new Button('Button 5');
		//button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 1, 1);
		
		var button = new Button('Button 6');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button, 1, 2, 1, 2);
	}
	
	function simpleGridLayoutTest()
	{
		var container = new Container<SimpleGridLayout>(new SimpleGridLayout(true, 10));
		_container = cast container;
		container.addTo(this);
		
		var layout = container.layout;
		layout.autoSize = false;
		
		var button = new Button('Button              00');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
		
		var button = new Button('Button     10');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
		
		var button = new Button('Button    0102');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
		
		var button = new Button('Button                20');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
		
		var button = new Button('Button       05');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
		
		var button = new Button('Button   1525');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
		
		var button = new Button('Button 31');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
		
		var button = new Button('Button 32');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
		
		layout.add(new Spacer().setXSize(100, 100, 50).setYSize(0, 100, 0, 100));
		
		var button = new Button('Button 14');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
		
		layout.add(new Spacer().setXSize(100, 100).setYSize(0, 100, 0, 20));
		
		var button = new Button('Button 3334');
		button.percentsWidth = 100;
		button.percentsHeight = 100;
		layout.add(button);
	}
	
	override function resize(width:Float, height:Float)
	{
		if (_tf == null)
		{
			_tf = new TextField();
			addChild(_tf);
		}
		var time = Lib.getTimer();
		_container.width = width - 150;
		_container.height = height - 100;
		_tf.text = 'time: ' + (Lib.getTimer() - time);
	}
}